﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace BtoBSWT315.Company
{
    /// <summary>
    /// Connection 的摘要说明。
    /// </summary>
    /// 
    public partial class Connection : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label qymc;
        protected System.Web.UI.WebControls.Image Image1;
        protected System.Web.UI.WebControls.HyperLink HyperLink1;
        protected System.Web.UI.WebControls.HyperLink HyperLink2;
        protected System.Web.UI.WebControls.HyperLink HyperLink3;
        protected System.Web.UI.WebControls.HyperLink HyperLink4;
        //protected System.Web.UI.WebControls.HyperLink qymc1;
        protected System.Web.UI.WebControls.HyperLink HyperLink6;
        protected System.Web.UI.WebControls.Label qymc2;
        protected System.Web.UI.WebControls.Label address;
        protected System.Web.UI.WebControls.Label phone;
        protected System.Web.UI.WebControls.Label fax;
        protected System.Web.UI.WebControls.Label mobile;
        protected System.Web.UI.WebControls.Label email;
        protected System.Web.UI.WebControls.Label lxman;
        //protected System.Web.UI.WebControls.Button SubMit;
        //protected System.Web.UI.WebControls.Button Reset;
        protected System.Web.UI.WebControls.TextBox Linkman;
        protected System.Web.UI.WebControls.TextBox content;
        protected System.Web.UI.WebControls.TextBox phone1;
        protected System.Web.UI.WebControls.Literal Literal1;

        public int CompanyID;
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (!IsPostBack)
            {
                QYDataBind();
                //CDataBind();
            }
        }


        private void QYDataBind()
        {
            int gsid = Convert.ToInt32(Request.QueryString["ID"]);
            CompanyID = gsid;

            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            string sql = "select qymc,address,phone,fax,name,mobile,email from Qyml where ID=" + gsid;
            DataTable dataTable = new DataTable();
            dataTable = classdb.GetTables(sql);
            foreach (DataRow row in dataTable.Rows)
            {
                Literal1.Text = row["qymc"].ToString();
                //qymc.Text = row["qymc"].ToString();				//企业名称
                //qymc1.Text = row["qymc"].ToString();				//企业名称
                qymc2.Text = row["qymc"].ToString();				//企业名称
                address.Text = row["address"].ToString();			//企业地址
                phone.Text = row["phone"].ToString();				//企业电话
                fax.Text = row["fax"].ToString();				   //传真
                lxman.Text = row["name"].ToString();				//联系人
                mobile.Text = row["mobile"].ToString();			//手机
                email.Text = row["email"].ToString();				//邮箱

                //HyperLink1.NavigateUrl = "Default.aspx?ID=" + gsid;
                //HyperLink2.NavigateUrl = "Default.aspx?ID=" + gsid + "#02";
                //HyperLink3.NavigateUrl = "Default.aspx?ID=" + gsid + "#01";
                //HyperLink4.NavigateUrl = "Default.aspx?ID=" + gsid + "#03";
                //HyperLink6.NavigateUrl = "Jop.aspx?ID=" + gsid;
            }
            dataTable.Clear();
            dataTable.Dispose();

        }



        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        protected void Submit_Click1(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Linkman.Text) || String.IsNullOrEmpty(content.Text) || String.IsNullOrEmpty(phone1.Text))
            {
                Response.Write("<script>alert('请按要求输入');</script>");
                Response.Write("<script>history.go(-1);</script>");
                Response.End();
            }

             Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
             int gsid = Convert.ToInt32(Request.QueryString["ID"]);

            //定义所需SQL
            string sql = "insert into Messages (title,mail,linkman,gsid,phone,content,dateandtime)values('" + Title.Text.Trim() + "','" + zxemail.Text.Trim() + "','" + Linkman.Text.Trim() + "','" + gsid + "','" + phone1.Text.Trim() + "','" + content.Text.Trim() + "','" + DateTime.Now.ToString() + "')";

            //Response.Write(sql);
            //引入数据库操作类
           
            if (classdb.GetNonResult(sql) != 0)
            {
                Response.Write("<script>alert('操作成功');</script>");
                Response.Write("<script>history.go(-1);</script>");
                Response.End();
            }
            else
            {
                Response.Write("<script>alert('操作失败，请重试！');</script>");
                Response.Write("<script>history.go(-1);</script>");
                Response.End();
            }

        }

        protected void Reset_Click(object sender, EventArgs e)
        {
            Linkman.Text = "";
            phone1.Text = "";
            content.Text = "";
        }


    }
}
